﻿//创建时间: 2010-10-11
//创建作者: 李 城
//功能说明: 系统参数类型 添加 修改 
//最后修改: 2010-10-11
using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using TRPOP.Common;
using TRPOP.CMS.Web.UI;


using TRPOP.CMS.Business;
using TRPOP.CMS.Model;

namespace TRPOP.CMS.Web.Admin
{
    public partial class ParamType_save : BaseAdmin
    {
        #region 当前页面权限验证
        protected override void SubPageInit()
        {
            base.m_SubPagePermission = Plugin.PermissionKeys.PermissionEnum.SystemManage_SysParam;
        }
        #endregion


        #region 页面变量
        protected bool m_IsAdd = true;
        protected int m_cid = 0;
        ParamTypeManage oParamTypeManage = new ParamTypeManage();
        protected string m_linkStr = "";
        #endregion

        #region 页面事件

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadBase();
            }
            LoadData();
        }
        /// <summary>
        /// 添加或修改
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string strMSG = "参数名或参数关键字";
            if (!PageAssist.CheckForm(txtName, ref strMSG) || !PageAssist.CheckForm(txtKeyWords, ref strMSG))
            {
                Alert(strMSG);
                return;
            }
            ParamTypeInfo oParamTypeInfo = new ParamTypeInfo();
            int.TryParse(GetRequestViewState("cid"), out m_cid);

            oParamTypeInfo = oParamTypeManage.GetInfoById(m_cid);
            if (oParamTypeInfo == null)
            {
                oParamTypeInfo = new ParamTypeInfo();
            }
            oParamTypeInfo.IsSysParam = chkIsSysParam.Checked;
            oParamTypeInfo.KeyWord = txtKeyWords.Text.Trim();
            oParamTypeInfo.Name = txtName.Text.Trim();
            SubmitAlert(oParamTypeManage.Save(oParamTypeInfo));
        }
        #endregion

        #region 页面方法

        public void LoadBase()
        {
            int.TryParse(InitRequestViewState("cid"), out m_cid);
            //初始化textbox等的数据
            ParamTypeInfo oParamTypeInfo = oParamTypeManage.GetInfoById(m_cid);
            if (oParamTypeInfo != null)
            {
                chkIsSysParam.Checked = oParamTypeInfo.IsSysParam;
                txtKeyWords.Text = oParamTypeInfo.KeyWord;
                txtName.Text = oParamTypeInfo.Name;
                if (oParamTypeInfo.IsSysParam)
                    txtKeyWords.Enabled = false;
                else
                    txtKeyWords.Enabled = true;
                m_IsAdd = false;
            }
            else
            {
                m_IsAdd = true;
                txtKeyWords.Enabled = true;
            }
        }
        /// <summary>
        /// 加载所有参数类型的的链接页面
        /// </summary>
        public void LoadData()
        {
            //初始化快捷链接
            foreach (ParamTypeInfo TempInfo in oParamTypeManage.GetListByCondition(0, "", "ParamTypeId"))
            {
                m_linkStr += " | " + "<a href=\"ParamType_Save.aspx?cid=" + TempInfo.ParamTypeId.ToString() + "\" >" + TempInfo.Name + "</a>";
            }
        }
        #endregion
    }
}
